package auth

import (
	"context"

	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleBindAccountsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewRoleBindAccountsLogic 角色绑定多个账户
func NewRoleBindAccountsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleBindAccountsLogic {
	return &RoleBindAccountsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleBindAccountsLogic) RoleBindAccounts(req *types.RoleBindAccountsRequest) error {
	_, err := l.svcCtx.AuthRoleRpc.RoleBindAccounts(l.ctx, &v1.RoleBindAccountsRequest{
		RoleId:      req.RoleId,
		AccountIds:  req.AccountIds,
		AccountType: v1.AccountType(req.AccountType),
	})

	return err
}
